import  requests,unittest

# url='http://10.59.9.14:7003/api/public/login'
# method='POST'
# json={"username":"17733058407","password":"li123456"}
#
# print(requests)


class A3mall(unittest.TestCase):
    token = None
    dy=None
    #login 登录
    def test_A3mall_01_login(self):
        url = 'http://10.59.9.14:7003/api/public/login'
        json = {"username": "17733058407", "password": "li123456"}
        login = requests.post(url=url,
                              json=json)
        print(login.json())
        A3mall.token =login.json()['data']['token']
        A3mall.dy=login.json()['data']['group_name']
        self.assertIn('钻石',A3mall.dy)
        print(A3mall.token)
    #info 我的
    def test_A3mall_02_info(self):
        url='http://10.59.9.14:7003/api/ucenter/info'
        headers={'Auth-Token':'Bearer '+A3mall.token}
        info=requests.get(url=url,headers=headers)
        print(info.json())
    #send 签到
    def test_A3mall_03_send(self):
        url='http://10.59.9.14:7003/api/sign/send'
        headers={'Auth-Token':'Bearer '+A3mall.token}
        send=requests.get(url=url,headers=headers)
        print(send.json())

    #seach 搜索
    def test_A3mall_04_seach(self):
        url='http://10.59.9.14:7003/api/search'
        seach=requests.get(url=url)
        print(seach.json())

    # seach_list 搜索列表
    def test_A3mall_05_seach_list(self):
        spid=None
        url='http://10.59.9.14:7003/api/search/list?page=1&keywords=%E7%83%AD&type=0&sort=1'
        seach_list=requests.get(url=url)
        print(seach_list.json())
        A3mall.spid=seach_list.json()['data']['list'][0]['id']
        print(A3mall.spid)

    #商品详情
    def test_A3mall_06_view(self):
        url='http://10.59.9.14:7003/api/goods/view?id=39'
        view=requests.get(url=url)
        print(view.json())

    #加入购物车
    def test_A3mall_07_add(self):
        url='http://10.59.9.14:7003/api/cart/add'
        json={"id":39,"sku_id":"","num":1}
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        add=requests.post(url=url,json=json,headers=headers)
        print(add.json())

    #进入购物车
    goodsid=None
    def test_A3mall_08_jinru(self):
        url='http://10.59.9.14:7003/api/cart?page=1'
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        jinru=requests.get(url=url,headers=headers)
        print(jinru.json())
        A3mall.goodsid=jinru.json()['data']['list'][0]['id']
        print(A3mall.goodsid)


    #创建订单
    def test_A3mall_09_care(self):
        url='http://10.59.9.14:7003/api/order/confirm?id=22&type=cart&shipping_type=1'
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        json={"id":A3mall.goodsid,"type":"cart","address_id":6,"store_id":1,"shipping_type":1,"bonus_id":"0","payment":"balance","remarks":"","source":1,"url":"http://10.59.9.14:7003/wap/pages/cart/confirm?id=22&type=cart"}
        care=requests.get(url=url,headers=headers,json=json)
        print(care.json())

    #支付成功
    def test_A3mall_10_pay(self):
        url='http://10.59.9.14:7003/api/order/create'
        json = {'id': A3mall.goodsid}
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        pay=requests.post(url=url,headers=headers,data=json)
        print(pay.json())


    #查看订单
    def test_A3mall_11_find(self):
        url='http://10.59.9.14:7003/api/order/detail'
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        json={"id":"573"}
        find=requests.post(url=url,headers=headers,data=json)
        print(find.json())


    if __name__ == '__main__':
        unittest.main()